package org.wuyichun.eduserver.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.wuyichun.base.util.PageInfo;
import org.wuyichun.eduserver.domain.Employee;
import org.wuyichun.eduserver.mapper.EmployeeMapper;
import org.wuyichun.eduserver.query.EmployeeQuery;
import org.wuyichun.eduserver.service.IEmployeeService;

import java.io.Serializable;
import java.util.List;
@Service
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class EmployeeServiceImpl implements IEmployeeService {
    @Autowired
    private EmployeeMapper mapper;
    @Transactional
    @Override
    public void insert(Employee employee) {
        mapper.insert(employee);
    }
    @Transactional
    @Override
    public void delete(Serializable id) {
        mapper.delete(id);
    }
    @Transactional
    @Override
    public void update(Employee employee) {
        mapper.update(employee);
    }

    @Override
    public Employee selectById(Serializable id) {
        return mapper.selectById(id);
    }

    @Override
    public List<Employee> selectAll() {
        return mapper.selectAll();
    }

    @Override
    public Long queryTotal(EmployeeQuery employeeQuery) {
        return mapper.queryTotal(employeeQuery);
    }

    @Override
    public PageInfo<Employee> queryPage(EmployeeQuery employeeQuery) {
        // 高级查询和分页 只需要查 分页的数据 list = 10条 就OK了???  还要查total
        PageInfo<Employee> pageInfo = new PageInfo<>();
        Long total = mapper.queryTotal(employeeQuery);
        if(total != 0){
            List<Employee> employees = mapper.queryPage(employeeQuery);
            pageInfo.setList(employees);
            pageInfo.setTotal(total);
        }
        return pageInfo;
    }

    @Override
    public void batchDelete(List<Serializable> ids) {
        mapper.batchDelete(ids);
    }
}
